/*
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "./runrecordset.h"

RunRecordSet::RunRecordSet()
{

}

RunRecordSet::RunRecordSet(QString basedir)
{
  QDir dir(basedir);
  dir.setFilter(QDir::Dirs);
  dir.setNameFilters(QStringList(QString("20*")));

  QFileInfoList yearDirs = dir.entryInfoList();
  QFileInfo year;
  foreach(year, yearDirs)
  {
    QDir yearDir(year.absoluteFilePath());
    yearDir.setFilter(QDir::Dirs);
    
    QFileInfoList monthDirs = yearDir.entryInfoList();
    QFileInfo month;
    foreach(month, monthDirs)
    {
      QDir monthDir(month.absoluteFilePath());
      monthDir.setFilter(QDir::Files);
      monthDir.setSorting(QDir::Name);
      monthDir.setNameFilters(QStringList(QString("*.gmn")));
      QFileInfoList entryList = monthDir.entryInfoList();

      QFileInfo entry;
      foreach(entry, entryList)
      {
        RunRecord record(entry.absoluteFilePath());
        records.append(record);
      }
    }
  }
}

int RunRecordSet::size()
{
  return records.size();
}

RunRecord RunRecordSet::getRecord(int i)
{
  return records.value(i);
}
